package com.oa.interceptor;

import com.oa.entity.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * @author FengMengHuo
 * 登录拦截器
 */
public class LoginInterceptor implements Interceptor {
	private static final long serialVersionUID = 1L;
	// 重点来做拦截的方法
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext context = invocation.getInvocationContext();
		/*String path = ServletActionContext.getRequest().getRequestURI();
		path = path.substring(path.lastIndexOf("/"),path.length());
		System.out.println("===========>"+path);*/
		/*if(path.equals("login.jsp")){
			return invocation.invoke();
		}*/
		if(invocation.getProxy().getMethod().equals("login")){
			return invocation.invoke();
		}else{
			User user = (User) context.getSession().get("user1");
			System.out.println(user);
			if(user!=null)
				return invocation.invoke();
			else
				return "noLogin";
		}
	}
	// 销毁方法
	public void destroy() {
	}
	// 初始化方法
	public void init() {
	}

}
